﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using SportsStore.Domain.Abstract;
using SportsStore.Domain.Entities;
using SportsStore.WebUI.Controllers;

namespace SportsStore.UnitTests
{
    [TestFixture]
    public class CatalogBrowsing
    {
        [Test]
        public void Can_View_A_Single_Page_Of_Products()
        {
            // Arrange: If there are 5 products in the repository...
            IProductsRepository repository = UnitTestHelpers.MockProductsRepository(
            new Product { Name = "P1" }, new Product { Name = "P2" },
            new Product { Name = "P3" }, new Product { Name = "P4" },
            new Product { Name = "P5" }
            );
            var controller = new ProductsController(repository);
            controller.PageSize = 3; // This property doesn't yet exist, but by
            // accessing it, you're implicitly forming
            // a requirement for it to exist
            // Act: ... then when the user asks for the second page (PageSize=3)...
            var result = controller.List(2);
            // Assert: ... they'll just see the last two products.
            var displayedProducts = (IList<Product>)result.ViewData.Model;
            displayedProducts.Count.ShouldEqual(2);
            displayedProducts[0].Name.ShouldEqual("P4");
            displayedProducts[1].Name.ShouldEqual("P5");
        }
    }
}
